package com.edooschool.oral.arithmetic.dao;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.edooschool.entity.oral.OralAnswerRecord;
import com.edooschool.entity.oral.OralQuestion;
import com.edooschool.entity.oral.OralRound;
import com.edooschool.entity.oral.OralStat;

/**
 * 
 * @author mohanlan
 *
 */
@Dao("hibernate")
public interface OralArithmeticDao {
    
    /**
     * Load OralRound by id
     * 
     * @param id
     * @return
     */
    @Query("FROM OralRound WHERE id = :id AND disabled = false")
    public OralRound loadOralRound(@Variable("id") Long id);
    
    /**
     * Load oralStat by id
     * 
     * @param id
     * @return
     */
    @Query("FROM OralStat WHERE id = :id")
    public OralStat loadOralStat(@Variable("id") Long id);
    
    /**
     * list oral round by group
     * 
     * @param groupId
     * @return
     */
    @Query("FROM OralRound WHERE disabled = false AND group.id = :groupId")
    public List<OralRound> listOralRound(@Variable("groupId") Long groupId);
    
    /**
     * Load OralAnswerRecord by id
     * 
     * @param id
     * @return
     */
    @Query("FROM OralAnswerRecord WHERE id = :id")
    public OralAnswerRecord loadOralAnswerRecord(@Variable("id") Long id);
    
    /**
     * list oral question by id
     * 
     * @param ids
     * @return
     */
    @Query("FROM OralQuestion WHERE id in (:ids) AND disabled = false")
    public List<OralQuestion> listOralQuestion(@Variable("ids") List<Long> ids);
    
    /**
     * 
     * 
     * @param openid
     * @return
     */
    @Query("FROM OralAnswerRecord WHERE openid = :openid ORDER BY createTime DESC")
    public List<OralAnswerRecord> latestAnswerRecord(@Variable("openid") String openid);
    
    /**
     * 
     * @param openid
     * @param roundId
     * @return
     */
    @Query("FROM OralAnswerRecord WHERE openid = :openid AND oralRound.id = :roundId ORDER BY createTime DESC, stars DESC")
    public List<OralAnswerRecord> listOralAnswerRecord(@Variable("openid") String openid, @Variable("roundId") Long roundId);
}
